<?php
namespace app\admin\controller;
/*
 *  分红列表
 * */
use app\common\controller\Admin;
use think\facade\Db;
use think\facade\View;
use app\common\model\AuthGroup;
use app\common\model\AuthGroupAccess;

class Bonus extends Admin
{
    protected $modelClass = '\app\common\model\BonusLog';
    
    protected function setLang()
    {
        $this->searchArr = [
//            'a.id' => "ID",
            'a.date' => '发放批次',
//            'a.trade_hash' => '交易哈希',
        ];
    }
    
    public function index()
    {
        $this->_indexSearch();
        $where = [];
        $getSearch = $this->_getSearch();
        if (!empty($getSearch)) $where[] = $getSearch;

        $order = 'a.date desc';
        $dataList = $this->cModel
        ->alias('a')
        ->field('a.*')
        ->where($where)->order($order)->paginate('', false, page_param());
        $all_token_num = $this->cModel->alias('a')->where($where)->sum("all_token");
        $real_token_num = $this->cModel->alias('a')->where($where)->sum("real_token_num");
        View::assign('all_token_num', $all_token_num);
        View::assign('real_token_num', $real_token_num);
        View::assign('dataList', $dataList);
        return View::fetch();
    }

    public function detail_list()
    {
        $log_id = $this->request->get("log_id");
        $log_info = $this->cModel->where("id",$log_id)->field("date,suffix")->find();
        $suffix = $log_info['suffix'] ?? '';
        $this->_indexSearch();
        $where = [];
        $where[] = ['log_id','=',$log_id];
        $getSearch = $this->_getSearch();
        if (!empty($getSearch)) $where[] = $getSearch;
        $order = 'a.token desc';
        $dataList = Db::name("bonus_detail_list{$suffix}")->alias('a')
            ->field('a.*')->where($where)->order($order)->paginate('', false, page_param());
        View::assign('dataList', $dataList);
        View::assign('date', $log_info['date'] ?? '');
        return View::fetch();
    }

}